import random
from datetime import datetime
def shop():
    coupon = random.randint(1, 10)
    print(f"恭喜你获得{coupon}折优惠，请尽情购物吧")
    money=float(input("输入你的钱:"))
    product={'水杯':100,'电脑':200,'耳机':300}
    shop_list=[]
    time_list=[]
    while True:

        shangpin=input("输入你要购买的商品(输入q退出购买界面):").strip().lower()
        if shangpin == 'q':
            break

        if shangpin in product:
            price = product[shangpin]
            coupon_price=price*coupon*0.1

            if coupon_price<=money:

                shop_list.append(shangpin)
                tuikuan=input("是否确认购买并付款，如果需要取消请输入b，如需继续请按回车:").strip().lower()
                if tuikuan == 'b':
                    money=money
                    # current_datetime=datetime.now()
                    # time_list.append(current_datetime)
                    shop_list.remove(shangpin)
                    print(f"商品{shangpin}已退回至购物架")
                    print(f"当前卡上余额:{money}")
                else:
                    money=money-coupon_price
                    current_datetime=datetime.now()
                    time_list.append(current_datetime)
                    print(f"恭喜购买成功！卡上余额还有{money}")

            else :
                print("穷鬼，钱不够")
        else:
            print("没有这个商品，别瞎弄")

    print("---正在打印购物小票---")
    print(f"打印购物小票:你购买了{','.join(shop_list)}")
    for item in time_list:
        time = item
        print(f"购买时间为:{time}")
    print(f"购物数量:{len(shop_list)}个")
    print(f"总价值:{sum(product[item] for item in shop_list)}元")
    print(f"卡上余额:{money}元")
shop()
 